package net.kangyee.eventmanager.commands;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.kangyee.eventmanager.EventManager;
import net.kangyee.eventmanager.util.MessageManager;

public class CmdFreeze extends EventManagerCommand {
	
	private EventManager plugin;
	
	public CmdFreeze(EventManager plugin){
		this.plugin = plugin;
	}

	public void onCommand(Player player, String[] args){
        if(args.length == 2){
        	if(!plugin.playerStateChecker(player, args[1])){
        		return;
        	}
            if (plugin.regPlayers.get(Bukkit.getPlayer(args[1]))){
            	MessageManager.sendNormalMessage(player, "&c该玩家已经被设置为禁止移动了");
                return;
            }
            Player targetPlayer = Bukkit.getPlayer(args[1]);
            plugin.setMoveState(targetPlayer, true);
            MessageManager.sendNormalMessage(player, "玩家&6" + player.getName() + "&f被你设置为禁止移动");
        	MessageManager.sendAdminMessage(targetPlayer, "你被管理员设置为禁止移动");   		
        	return;
        }else{
        	for(Player localPlayer : plugin.regPlayers.keySet()){
        		plugin.setMoveState(localPlayer, true);
        		MessageManager.sendAdminMessage(localPlayer, "你被管理员设置为禁止移动");   	
            }
        	MessageManager.sendNormalMessage(player, "所有参加活动的玩家被你设置为禁止移动");
        	return;
        }
	}

	public String getCmdName(){
		return "freeze";
	}

	public String getArgs(){
		return "[游戏名]";
	}
	
	public int getMaxArgs(){
		return 2;
	}

	public int getMinArgs(){
		return 1;
	}

	public String getPermission(){
		return "eventmanager.admin." + getCmdName();
	}

	public boolean getStateRequire(){
		return true;
	}
	
	public boolean getRegPCRequire() {
		return true;
	}
}
